
view browse "https://gitee.com/MoRanHuiShou2017"


//软件安装，介绍，外部命令安装等。

adoedit xthreg.ado //其他人编写的外部命令

adoedit wl.ado

cd "C:\Users\Lisheng\Desktop\统计学" //进入当前所在目录

//看下什么是变量

*调入自带的数据

sysuse auto,clear 

import excel "例3.1.xlsx",firstrow clear 

*第二章填充数据

view browse "https://mp.weixin.qq.com/s/p-n-mxd4Ay8jl3IujUk7pQ"


* 给统计学成绩排序

sort 统计学成绩

*列出后三名
list 统计学成绩 数学成绩 in 1/3

gsort 统计学成绩

gsort -统计学成绩

list 统计学成绩 数学成绩 in 1/3

egen mean1 = mean(统计学成绩)

gen mean2 = (统计学成绩+数学成绩+英语成绩+经济学成绩)/4


adoedit sq.ado

*数据分类展示

import excel "例3.2.xlsx",firstrow clear 

tabulate 顾客性别 

tabulate 饮料类型

sencode 饮料类型,gen(type)

tabulate type

tabulate 饮料类型 顾客性别

sencode 顾客性别,gen(sex)

*绘图

*1. 直方图
import excel "例3.3.xlsx",firstrow clear 

set scheme cleanplots

histogram 销售量,start(141) width(10) xlabel(141(10)241) ///
	xtick(141(10)241) ylabel(0(5)30,grid gmax) plotregion(style(none)) xtitle(`"{fontface "宋体":销售量}"')  frequency normal addlabels addlabopts(mlabcolor(blue))

graph save fig1.gph,replace 
graph export fig1.png,replace 

*2.箱型图
import excel "例3.4.xlsx",firstrow clear 

save data.dta,replace 

local j=1
foreach var of varlist *学院{
	use data,clear 
	keep `var'
	gen id =`j'
	gen name="`var'"
	rename `var' score
	save `j'.dta,replace 
	local j=`j'+1
}

use 1.dta,clear 

forvalues j=2/5{
	append using `j'.dta
}

set scheme s1mono
graph box score,marker(1, msymbol(Oh) msize(small)) over(name)

help graph box 

*3. 散点图

import excel "例3.5.xlsx",firstrow clear 

scatter 体重 身高

scatter 体重 身高 || lfit 体重 身高

twoway (scatter 体重 身高) (lfitci 体重 身高)  // 图层的概念

* 4. 雷达图
cnssc install spider, replace
import excel "例3.6.xlsx",firstrow clear 

spider 食品烟酒-其他, over(地区) scolor(black*0.4) palette(plottig)

/*
set scheme cleanplots
spider 食品烟酒-其他, over(地区)
*/

*适度性度量

import excel "例4.1.xlsx",firstrow clear 

sum,d

*-----表1 变量的基本统计-------
global vv "网购金额"
tabstat $vv , s(mean sd min med max skewness kurtosis N) f(%6.3f) c(s)

*将基本统计导入到word中
sum2docx $vv using "表1描述性统计.docx",replace     ///
  stats(N mean(%6.3f) sd(%6.3f) median min max skewness kurtosis )  ///
  title("表1 描述性统计") font("Times New Roman",10.5,"black") ///
  note("this is Summary Statistics") pagesize(A4)

sysuse auto,clear 
global vv "price rep78 len wei foreign"
tabstat $vv , s(mean sd min med max skewness kurtosis N) f(%6.3f) c(s)

*将基本统计导入到word中
sum2docx $vv using "表2描述性统计.docx",replace     ///
  stats(N mean(%6.3f) sd(%6.3f) median min max skewness kurtosis )  ///
  title("表2 描述性统计") font("Times New Roman",10.5,"black") ///
  note("this is Summary Statistics") pagesize(A4)


*基本统计

view browse "https://mp.weixin.qq.com/s?__biz=MzU4Nzc5OTE0NQ==&mid=2247484104&idx=1&sn=c7766321f42d2082f5cd2c23b87c0b13&chksm=fde7cdceca9044d85d4e86f3d2c6d05e294896bf96e3458033b8008d557bfe9a864c687c1313&token=834296224&lang=zh_CN#rd"
























